﻿using System.Diagnostics;

namespace IsolatedPerformanceTests
{
    public class PerfMeter
    {
        private readonly Stopwatch stopwatch = new Stopwatch();
        public string TestName { get; set; }

        public PerfMeter(string testName, bool startNow)
        {
            this.TestName = testName;
            if (startNow)
                Start();
        }

        public void Start()
        {
            stopwatch.Start();
        }

        public double Stop()
        {
            stopwatch.Stop();
            ElapsedMiliseconds = (stopwatch.ElapsedTicks * 1000.0) / Stopwatch.Frequency;
            stopwatch.Reset();
            return ElapsedMiliseconds;
        }

        private double ElapsedMiliseconds { get; set; }

        public override string ToString()
        {
            return TestName + ": " + ElapsedMiliseconds + "ms";
        }
    }
}
